package com.million.controller;

import com.million.base.EvictionStrategyLoopFactory;
import com.million.service.EvictionStrategyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.lang.reflect.InvocationTargetException;
import java.util.Map;

/**
 * @Author miki
 * @Date 2022/1/22 1:00
 * @Explain 淘汰策略测试
 */
@Slf4j
@Controller
@RequestMapping("/eviction")
public class EvictionController {

    @Autowired
    EvictionStrategyService evictionStrategyService;

    @GetMapping("/{eviction}")
    @ResponseBody
    public Map<String, Object> getEvictionSelect(@PathVariable("eviction") String eviction) throws InvocationTargetException,
            NoSuchMethodException, InstantiationException, IllegalAccessException {
        return EvictionStrategyLoopFactory.clientSelect(eviction).evictionCache();
    }

    @PostMapping("/{eviction}")
    @ResponseBody
    public Map<String, Object> evictionSelect(@PathVariable("eviction") String eviction) {
        return evictionStrategyService.select(eviction).evictionCache();
    }
}
